<?php
namespace View;

class quizView{
	
	/**
	 * @var $loginButton (Loginbutton for all users and admins)
	 * @var $createNewQuizButton (Button for creating quizzes, for admins)
	 * @var $userName (The posted username)
	 * @var $passWord (The posted password)
	 * @var $nameValue (Saved username for viewing purposes)
	 * @var $quizName (The name of a quiz)
	 * @var $numberOfQuestions (The number of questions in said quiz)
	 * @var $nextStepButton (Button for moving on to the second step of creating a quiz)
	 * @var $abortButton (Abort creation of a quiz)
	 * @var $finished (Finish creating the quiz)
	 */
	private static $loginButton = "self::LoginButton";
	private static $createNewQuizButton = "self::createNewQuizButton";
	private static $userName = "self::userName";
	private static $passWord = "self::passWord";
	private static $nameValue = "";
	private static $quizName = "self::quizName";
	private static $numberOfQuestions = "self::numberOfQuestions";
	private static $nextStepButton = "self::nextStepButton";
	private static $abortButton = "self::abortButton";
	private static $finished = "self::finished";
	private static $question = "self::question";
	private static $answerOption = "self::answerOption";
	private $message = "";
		
	/**
	 * @return string (html)
	 */	
	public function getLoginPage(){
		return "<h2>Var vänlig logga in för att börja quizza!</h2>
				<form action='?' method='post'>		
						<label for='User' >Användarnamn :</label>
						<input type='text' size='30' name='" . self::$userName . "' id='User' value='" . self::$nameValue . "' />
						<label for='PassWord' >Lösenord  :</label>
						<input type='password' size='30' name='" . self::$passWord . "' id='PassWord' value='' />
						<input type='submit' name='" . self::$loginButton . "' value='Logga In' />
				</form>";
	}
	
	/**
 	 * @return string (html)
	 */	
	public function getAdminPage(){
		return "<h2>Admin-interface</h2>
				<p>Här ska det in en lista med befintliga quiz som admin ska kunna modifiera.</p>
				<form action='?' method='post'>
					<input type='submit' name='" . self::$createNewQuizButton . "' value='Skapa nytt Quiz!' />
				</form>";
	}
	
	/**
	 * @return string (html)
	 */
	public function getQuizList($quizlist){
		$html = "";	
			
		foreach($quizlist as $quiz){
			$html .= "<a href=''>" . $quiz->quizName . "</a>";
		}
		
	 	return $html;
	}
	 
	 /**
	  * @return string (html)
	  */
	public function getCreateQuizPage(){
	  	return "<div>" . $this->message . "</div>
	  			<form action='?' method='post'>		
	  				<label for='Quizname'>Vad ska ditt quiz heta?</label>
	  				<input type='text' name='" . self::$quizName . "' id='Quizname' />
	  				<label for='Questioncount'>Hur många frågor vill du ha i ditt quiz?</label>
	  				<input type='text' length='2' maxlength='2' name='" . self::$numberOfQuestions . "' id='Questioncount' />
	  				<input type='submit' name='" . self::$nextStepButton . "' value='Gå vidare' />
	  				<input type='submit' name='" . self::$abortButton . "' value='Avbryt' />
				</form>";
	}
	  
	/**
	 * @return string (html)
	 */
	public function getCreateQuizPageTwo($quizName){	
	  	return "<div>" . $this->message . "</div>
	  			<h2>" . $quizName . "</h2>
	  		  	<div id='info'>
		  			<p>Skriv dom frågor du vill ha, och därefter de olika svarsalternativen tilll varje fråga.</p>
		  			<p>Kom ihåg att markera vilket av svaren som är det korrekta genom att markera detta i den runda 'plutten'.</p>	
	  			</div>
	 			<form action='?' method='post'>";			  	
	}

	/**
	 * @return string (html)
	 */
	public function generateQuestions($i){
		return "<div>" . $this->message . "</div>
				<label for='" . $i . "'>Fråga nummer " . $i . "</label>
				<textarea cols='50' rows='4' name='" . self::$question . $i . "' id='" . $i . "'></textarea>
				<input type='radio' name='" . $i . "' value='A' />
				<p>Svar 1</p><input type='text' name='" . self::$answerOption . $i . "1' id=''/>
				<input type='radio' name='" . $i . "' value='B' />
				<p>Svar 2</p><input type='text' name='" . self::$answerOption . $i . "2' id=''/>
				<input type='radio' name='" . $i . "' value='C' />
				<p>Svar 3</p><input type='text' name='" . self::$answerOption . $i . "3' id=''/>";
	}
	 
	/**
	 * @return string (html)
	 */
	public function closeForm(){
		return "<input type='submit' name='" . self::$finished . "' value='Klart!' />
				  </form>";
	}
	
	/**
	 * Functions to set error message if there is faulty input, no params or return
	 */
	public function createQuizStageOneFailed(){
		if(strlen($this->getQuizName() == "") || strlen($this->getQuizName()) < 4){
			$this->message .= "<p>Quiznamnet har för få bokstäver!</p>";
		}
		if(strlen($this->getQuizName()) > 20 && $this->getQuizName() != ""){
			$this->message .= "<p>Quiznamnet har för många bokstäver!</p>";
		}
		if(!(is_numeric($this->getNumberOfQuestions()))){
			$this->message .= "<p>Antalet frågor måste skrivas med siffror!</p>";
		}
		if($this->getNumberOfQuestions() > 5){
			$this->message .= "<p>Antalet frågor får ej överstiga fem!</p>";
		}
	}
	
	public function createQuizStageTwoFailed(){
		$this->message .= "<p>Ett eller flera fält saknar information!</p>";
	}
	 
	/**
	 * @return boolean (Wether or not loginbutton has been clicked)
	 */
	public function loginAttempt(){
		return isset($_POST[self::$loginButton]);
	}
	  
	/**
	 * @return boolean (checks for input for creating new quizes)
	 */
	public function createNewQuizAttempt(){
	   	return isset($_POST[self::$createNewQuizButton]);
	}
	   
	/**
	 * @return boolean (checks if admin moves on to the next step in creating a quiz)
	 */
    public function createNewQuizStageTwo(){
    	return isset($_POST[self::$nextStepButton]);
    }
    
    /**
	 * @return boolean (checks if admin clicks to finish quizcreation)
	 */
	public function finishQuizCreation(){
		return isset($_POST[self::$finished]);
	}
    
	/**
	 * @return string (Username)
	 */
	public function getUserName(){
		if(isset($_POST[self::$userName])){
			return $_POST[self::$userName];
		}
		else{
			return "";
		}
	}

	/**
	 * @return string (Password)
	 */
	public function getPassWord(){
		if(isset($_POST[self::$passWord])){
			return $_POST[self::$passWord];
		}
		else{
			return "";
		}
	}
	
	/**
	 * @return string (Quizname)
	 */
	public function getQuizName(){
		if(isset($_POST[self::$quizName])){
			return $_POST[self::$quizName];
		}
		else{
			return "";
		}
	}
	
	/**
	 * @return integer (Number of questions)
	 */
	public function getNumberOfQuestions(){
		if(isset($_POST[self::$numberOfQuestions])){
			return $_POST[self::$numberOfQuestions];
		}
		else{
			return 0;
		}
	}
	
	/**
	 * @param $i (The index of the answer)
	 * 
	 * @return string (String with question)
	 */
	public function getSelectedQuestion($i){
		if(isset($_POST[self::$question . $i])){
			$_POST[self::$question . $i];
		}
	}
	
	/**
	 * @param $i (The index of the answer)
	 * 
	 * @return string (The selected answer)
	 */
	public function getSelectedAnswer($i){
		if(isset($_POST[$i])){
			return $_POST[$i];
		}
	}
	 
	/**
	 * @param $i (Index)
	 * 
	 * @return string (The selected answeroption)
	 */
	public function getSelectedAnswerOption1($i){
		if(isset($_POST[self::$answerOption . $i . "1"])){
			return $_POST[self::$answerOption . $i . "1"];
		}
	}
	
		/**
	 * @param $i (Index)
	 * 
	 * @return string (The selected answeroption)
	 */
	public function getSelectedAnswerOption2($i){
		if(isset($_POST[self::$answerOption . $i . "2"])){
			return $_POST[self::$answerOption . $i . "2"];
		}
	}
	
		/**
	 * @param $i (Index)
	 * 
	 * @return string (The selected answeroption)
	 */
	public function getSelectedAnswerOption3($i){
		if(isset($_POST[self::$answerOption . $i . "3"])){
			return $_POST[self::$answerOption . $i . "3"];
		}
	}
}
